﻿using GN.Pay.TradeChannel.WeiXin.Request;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.TradeChannel.WeiXin
{
    [Serializable]
    public class WeiXinJSAPIPayRequest : WeiXinServiceBase
    {
        public override string ChannelId
        {
            get
            {
                return "WeiXin.JSAPI";
            }
        }

        public override ChannelType ChannelType
        {
            get
            {
                return ChannelType.WebApp;
            }
        }

        public override string ChannelName
        {
            get
            {
                return "公众号支付";
            }
        }

        public override string TradeType
        {
            get
            {
                return "JSAPI";
            }
        }

        public override ITradePayApplyResult PayApply(IOrderPayApply order)
        {
            if (!string.IsNullOrWhiteSpace(order.ClientIP))
            {
                var clientIps = order.ClientIP.Split(',');
                if (clientIps!=null&&clientIps.Length>1)
                {
                    order.ClientIP = clientIps.FirstOrDefault();
                }
            }
            var config = this.channelConfigure;
            var request = new JsApiPayRequest(this, order, config);
            return request.Build(this, config);
        }
    }
}
